package com.zjy.business.system.manager.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zjy.business.system.domain.manager.form.ManagerSysMenuSaveOrUpdateForm;
import com.zjy.business.system.domain.manager.vo.ManagerSysMenuListVo;
import com.zjy.business.system.manager.service.ManagerSysMenuService;
import com.zjy.log.annotation.OperationLog;
import com.zjy.log.enums.LogBusinessType;
import com.zjy.web.domain.model.Result;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 后台管理-菜单管理
 */
@RestController
@RequestMapping("/manager/sysMenu")
@RequiredArgsConstructor
@Validated
@Slf4j
public class ManagerSysMenuController {

    final private static String MODULE_NAME = "菜单管理";
    final private ManagerSysMenuService managerSysMenuService;

    /**
     * 新增或修改菜单信息
     */
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.INSERT_UPDATE)
    @PostMapping("/saveOrUpdate")
    @SaCheckPermission("system:sysMenu:save_update")
    public Result<Void> saveOrUpdate(@RequestBody ManagerSysMenuSaveOrUpdateForm form) {
        managerSysMenuService.saveOrUpdate(form);
        return Result.SUCCESS();
    }


    /**
     * 删除菜单
     * @param id 菜单id
     */
    @OperationLog(title = MODULE_NAME, logBusinessType = LogBusinessType.DELETE)
    @GetMapping("/remove")
    @SaCheckPermission("system:sysMenu:remove")
    public Result<Void> remove(@NotNull(message = "id不能为空") Long id) {
        managerSysMenuService.remove(id);
        return Result.SUCCESS();
    }

    /**
     * 获取菜单列表
     */
    @GetMapping("/getSysMenu")
    public Result<List<ManagerSysMenuListVo>> getSysMenu() {
        return Result.SUCCESS(managerSysMenuService.getSysMenu());
    }


}
